import React from 'react'
import PropTypes from 'prop-types'
import { Form, Input } from 'antd'

class AddUpdateForm extends React.Component {
    // 声明接收父组件的函数或值
    static propTypes = {
        setForm:PropTypes.func.isRequired,
        categoryName: PropTypes.string
    }

    // 将自身的值传递给父组件
    UNSAFE_componentWillMount(){
        // console.log(this)
        this.props.setForm(this.props.form)
    }

    render() {
        const { getFieldDecorator } = this.props.form;
        return (
            <div>
                <Form>
                    <Form.Item>
                        {
                            getFieldDecorator('categoryName', {
                                // 传递初始值
                                initialValue:this.props.categoryName,
                                rules: [{ required: true, message: '请填写分类信息' }],
                            })(<Input placeholder="请填写分类信息" />,)
                        }
                    </Form.Item>
                </Form>
            </div>
        )
    }
}

const WrappedAddUpdateForm = Form.create()(AddUpdateForm);

export default WrappedAddUpdateForm

/**
 * 表单验证
 * const { getFieldDecorator } = this.props.form;
 * {getFieldDecorator('标识名称'，{配置对象 initialValue=""（初始值）,rules:[{规则内容}]})(存放需要渲染的HTML标签)}
 */